<!--
@fucntion: 大创项目-申报
-->
<template>
  <el-row class="dachuang-declaration">
    <el-col style="height:100%;">
      <table-panel v-show="!declarationDlgVisible" :name="'大学生创新创业训练计划项目-项目申报'" :columns="declarationColumns" :tableData="declarationData" :showRowNumber="false" :multiSelection="true"
      :canExport="false" :customBtns="customBtns"
      :currentPage="declarationCurrentPage" :totalNum="declarationTotalNum" @page-change="onPageChange('declaration',$event)" :pageSize="pageSize"
      @table-searching="onSearching('declaration',$event)"
      @table-create="onCreate('declaration',$event)" @table-edit="onEdit('declaration', $event)"
      @table-delete="onDelete('declaration',$event)" @table-export="onExport('declaration',$event)"
      @selection-change="onSelectionChange('declaration',$event)"></table-panel>
      <dec-form v-show="declarationDlgVisible" @form-close="onCloseForm"
      :formRecord="declarationRecord"
      :formRules="declarationRules"></dec-form>
    </el-col>
  </el-row>
</template>
<script>
import TablePanel from "@/components/basic/TablePanel";
import {
  formModelInitFromTable,
  formRulesInitFromTable
} from "@/utils/formutils.js";
import { trueFalseRenderer } from "@/utils/tableutils.js";
import Form from "./declaration/Form";

//meta info
var declaration = "declaration"; // 表格名称
var columnsAttr = "Columns"; // 列
var dataAttr = "Data"; // 数据
var selectionAttr = "Selection"; // 选中
var dlgVisibleAttr = "DlgVisible"; // 对话框
var formAttr = "Form";
var recordAttr = "Record"; // 表单模型
var rulesAttr = "Rules"; // 表单验证
var curPageAttr = "CurrentPage";// 分页-当前页
var totalNumAttr = "TotalNum";// 分页-总数
var qParamAttr = "QueryParams";// 查询参数


var declarationColumns = [
  {
    prop:"xmsbbh",
    label:"项目申报编号",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xmmc",
    label:"项目名称",
    rules:[{
      required:true,
      message:"必填"
    }]
  },
  {
    prop:"xmlx",
    label:"项目申报类型",
    rules:[{
      required:true,
      message:"必填"
    }]
  },
  {
    prop:"xmlb",
    label:"项目申报类别",
    rules:[{
      required:true,
      message:"必填"
    }]
  },
  {
    prop:"ssyjxkmc",
    label:"所属一级学科名称",
    hidden:true,
    rules:[{
      required:true,
      message:"必填"
    }]
  },
  {
    prop:"xh",//学号
    label:"项目主持人编号",
    hidden:true
  },
  {
    prop:"xm",
    label:"项目主持人"
  },
  {
    prop:"xybh",
    label:"所属学院编号",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xymc",
    label:"所属学院"
  },
  {
    prop:"njbh",
    label:"年级编号",
    hidden:true
  },
  {
    prop:"njmc",
    label:"年级名称",
    hidden:true
  },
  {
    prop:"jsbh",//教师编号
    label:"指导教师编号",
    outOfSearch:true,
    hidden:true,
    rules:[{
      required:true,
      message:"请选择指导教师"
    }]
  },
  {
    prop:"jsxm",//教师姓名
    label:"指导教师"
  },
  {
    prop:"dw",
    label:"教师所在单位",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"jszc",
    label:"教师职称",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"wcsj",
    label:"完成时间",
    type:"date",
    outOfSearch:true,
    hidden:true,
    rules:[{
      required:true,
      message:"必填"
    }]
  },
  {
    prop:"tbrq",
    label:"填表日期",
    type:"date",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xmjs",
    label:"项目介绍",
    rules:[{
      required:true,
      max:5000
    }]
  },
  {
    prop:"xmzwpj",
    label:"项目自我评价",
    rules:[{
      required:true,
      max:5000
    }]
  },
  {
    prop:"xmcg",
    label:"项目成果",
    rules:[{
      required:true,
      max:5000
    }]
  },
  {
    prop:"ckwx",
    label:"参考文献",
    rules:[{
      required:true,
      max:5000
    }]
  },
  {
    prop:"jsjj",//教师简介
    label:"当前从事的教学研究工作简介",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"dxspj",//对学生评价
    label:"对申请人的专业基础、工作态度、学风及研究能力的评价",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"dxmpj",//对项目评价
    label:"对申请课题的价值、研究方案的可行性、工作基础等方面的评价",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"jsqzrq",//教师签字时间
    label:"教师签字时间",
    type:"date",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xxlxzzjf",
    label:"学校立项资助经费",
    type:"number",
    hidden:true
  },
  {
    prop:"xyptzzjf",
    label:"学院配套资助经费",
    type:"number",
    hidden:true
  },
  {
    prop:"qtjf",
    label:"其他经费",
    type:"number",
    hidden:true
  },
  {
    prop:"szxyshyj",
    label:"所在学院审核意见",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"szxyshrq",
    label:"所在学院审核日期",
    type:"date",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"zjpsyj",
    label:"专家评审意见",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"zjpsrq",
    label:"专家评审日期",
    type:"date",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xxspyj",
    label:"学校审批意见"
  },
  {
    prop:"xxsprq",
    label:"学校审批日期",
    type:"date",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"spjg",//是否同意
    label:"审批结果",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"spzzje",//审批成功后的资助金额
    label:"审批资助金额",
    type:"number",
    outOfSearch:true,
    hidden:true
  },
  {
    prop:"xmzt",
    label:"项目状态"
  }
];

export default {
  name:"Declaration",
  components: {
    "table-panel": TablePanel,
    "dec-form":Form
  },
  methods: {
    onSearching: function(tname, params) {
      var me = this;
      let url = "/static/data/declaration.json";// /static/data/faculty.json

      if(url !== "") {
        me[tname+qParamAttr] = {};
        me[tname+qParamAttr] = params;
        if (params.isAccurate) {
          me[tname+qParamAttr] = params.paramPairs;
        } else {
          me[tname+qParamAttr].keywords = params.query;
        }
        me.getRequest(url, me[tname+qParamAttr]).then(resp => {
            if(resp.status == 200) {
              me[tname+dataAttr] = resp.data.results;
              me[tname+totalNumAttr] = resp.data.total;
            }
        });
      }
    },
    onCreate: function(tname) {
      // 新增
      var me = this;
      me[tname+recordAttr] = formModelInitFromTable(me[tname+columnsAttr]);
      me[tname+recordAttr].sfqy = "1";// 创建时，有效否是选中的

      me[tname+dlgVisibleAttr] = true;
    },
    onEdit: function(tname, row) {
      // 编辑
      var me = this;
      me[tname + recordAttr]= row;
      me[tname + dlgVisibleAttr] = true;
    },
    onDelete: function(tname, row) {
      // 删除
      var me = this;
      me.$confirm("确定删除这条记录吗?", "提示", {
        type: "warning"
      }).then(() => {
        me.deleteRequest(`/????/${row.xmsbbh}`).then((resp)=>{
          if(resp.status == 200) {
            me.$message.success("删除成功!");
            me.onSearching(declaration,{});// 重新加载表格数据
          }else{
            me.$message.error("删除失败！");
          }
        });
      }).catch(() => {});
    },
    onExport: function(tname, params) {
      // 导出
      var me = this;
      me.$message.info("发送导出请求，返回下载路径");
    },
    onSelectionChange: function(tname, data) {
      // 选中改变
      var me = this;
      // 缓存记录，按照角色编号，查询对应的选中权限节点数组
      me[tname+selectionAttr] = data;
    },
    onConfirm: function(tname) {
      // 对话框-确认
      var me = this;
      // 验证信息
      var ret;
      me.$refs[tname + formAttr].validate((result, what)=>{
        ret = result;
      });
      if(!ret){
        me.$message.error("表单信息有误");
        return;
      }
      // 发送请求
      me.postRequest("/static/data/testSuc.json").then((resp)=>{
        if (resp.status == 200) {
          me.$message.success("提交成功！");
          //最后，隐藏对话框
          me[tname + dlgVisibleAttr] = false;
        } else {
          me.$message.error( "服务器发生错误，代码：" + resp.status);
        }
      });
    },
    onCloseForm:function(){
      var me = this;
      me[declaration + dlgVisibleAttr] = false;
      me[declaration+recordAttr] = formModelInitFromTable(me[declaration+columnsAttr]);// 初始化form的model
    }
  },
  data() {
    return {
      [declaration + columnsAttr]: declarationColumns, // 表格-列
      [declaration + dataAttr]: [], // 表格的数据
      [declaration + selectionAttr]: [], // 当前选中
      [declaration + dlgVisibleAttr]: false, // 对话框是否可见
      [declaration + recordAttr]: {}, // 表单模型
      [declaration + rulesAttr]: {}, // 表单验证
      [declaration + curPageAttr]:1,// 当前页
      [declaration + totalNumAttr]:0,// 总数
      [declaration + qParamAttr]:{},// 查询参数
      pageSize:20,// 每页数量
      customBtns:[{
        type:"success",
        text:"审批",
        icon:"el-icon-check",
        eventName:"table-approval"
      }]
    };
  },
  created: function() {
    var me = this;

    // 表单模型初始化
    me[declaration+recordAttr] = formModelInitFromTable(me[declaration+columnsAttr]);
    // 表单验证初始化
    me[declaration+rulesAttr] = formRulesInitFromTable(me[declaration+columnsAttr]);

  }
}
</script>
<style lang="scss">
.dachuang-declaration{
  height:100%;
}
</style>
